<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>添加新闻 | 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">

    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css">
    <link rel="stylesheet" href="/assets/css/amazeui.datetimepicker.css"/>
</head>
<body >
 {{template "admin/naver.html" .}}
        <!-- content start -->
        <div class="admin-content">
            <div class="admin-content-body">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf">
                        <strong class="am-text-primary am-text-lg" style=" color: #222222;">添加新闻</strong>
                    </div>
                </div>
                <hr>
                <div class="am-tabs am-margin" data-am-tabs >
                    <ul class="am-tabs-nav am-nav am-nav-tabs">
                        <li class="am-active"><a href="#tab1">填写信息</a></li>
                    </ul>
                    <div class="am-tabs-bd">
                        <div class="am-tab-panel am-fade am-in am-active" id="tab1">
		      <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">所属大类</div>
                                <div class="am-u-sm-8 am-u-md-10 ">
                                    <select id="BigDropList" onchange="changeSmall(this)" data-am-selected="{btnSize: 'sm'}">
										{{range $k,$v:=.BigList}}
                                        {{if $k}}
                                        <option value="{{$v.Id}}">{{$v.Name}}</option>
                                        {{else}}
                                        <option selected="selected" value="{{$v.Id}}">{{$v.Name}}</option>
                                        {{end}}
										{{end}}
                                    </select>
                                </div>
                            </div>
							 <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">所属小类</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <select id="SmallDropList" data-am-selected="{btnSize: 'sm'}">
                                        <option value="0">无</option>
                                    </select>
                                </div>
								{{range $k,$v:= .SmallVal}}<input type="hidden" id="smallval{{$k}}" value="{{$v}}">{{end}}
                            </div>
                             <form class="am-form">
                                <div class="am-g am-margin-top">

                                    <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                        文章标题
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-5">
                                        <input type="text" id="title" maxlength="510" onblur="checkRepeat()" class="am-input-sm" placeholder="请输入文章标题">
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-5" style=" color: red;">*</div>
                                </div>
                                <div class="am-g am-margin-top">
                                    <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                        发布作者
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-5 am-u-end col-end">
                                        <input type="text" id="author" maxlength="40" class="am-input-sm" placeholder="请输入作者">
                                    </div>
			<div class="am-hide-sm-only am-u-md-5"  style=" color: red;">*</div>
                                </div>
                                <div class="am-g am-margin-top">
                                    <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                        文章来源
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-5">
                                        <input type="text" id="origin" maxlength="40" class="am-input-sm" placeholder="请输入文章来源">
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-5"  style=" color: red;">*</div>
                                </div>

		  <div class="am-g am-margin-top">
                                    <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                        发布日期
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-5">
                                       <input type="text" id="date_now"  class="am-input-sm am-form-field"  readonly>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-5">*</div>
                                </div>

		<div class="am-g am-margin-top">
                                    <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                        点击次数
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-5">
                                    	<input type="text" id="hits_count" class="am-input-sm" maxlength="10" style="ime-mode:disabled" onkeyup="return ValidateNumber(this,value)" value="0"  />
                                        <!-- <input type="number" id="hits_count"  min="0"   class="am-input-sm" value="0" onchange="hits_func(this)"> -->
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-5">*</div>
                                </div>

                               <!-- <div class="am-checkbox" style="margin:20px 0 10px 280px;font-size:16px;">
                                    <label>
                                    <input type="checkbox" id="lunbotu" value="0" onchange="changecheckbox(this)"> 将本文第一张图片设为轮播图
                                    </label>
                                </div>-->

					<!--	<small style="margin-left:280px;color:#D02B4E">Tips：只有校园部分新闻图片会加入轮播图，并且只会选取最新几条新闻。</small><br>
						<small style="margin-left:315px;color:#D02B4E">添加图片时，请注意修改图片大小，避免阅读新闻时图片超出屏幕。</small>-->


   <div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-12 am-u-md-2  am-text-center admin-form-text">
                                        文章内容
                                    </div>
                                    <div class="am-u-sm-12 am-u-md-10">
                                        <script id="editor" type="text/plain" style="height:500px;width:702px;"></script>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="am-margin">
                    <button type="button" class="am-btn am-btn-secondary am-btn-sm" onclick="savesubmit()">添加新闻</button>
                    <button type="button" class="am-btn am-btn-secondary am-btn-sm" onclick="">放弃保存</button>
                </div>
            </div>
        </div>
       {{template "admin/footer.html" .}}

		   <script type="text/javascript" charset="utf-8" src="/assets/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/assets/ueditor/lang/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/laydate/laydate.js"></script>
 <script type="text/javascript">
	 var ue = UE.getEditor('editor');
      ue.autoHeightEnabled = false;

        function checkRepeat(){
			var $bid=$("#BigDropList").val().trim();
			var $sid=$("#SmallDropList").val().trim();
            var $title=$("#title");
            if ($title.val().trim()==='') {
                return ;
            }
            $.lintul('/admin/article/ct',{title:$title.val(),bid:$bid,sid:$sid},function(data){
                if (data.status===1) {
                    layer.msg('新闻题目不能重复', {icon:0, offset: '25%'});
                     $title.focus();
                }
            });
        }
		function changecheckbox(obj){
			obj.value= obj.value==="1"?"0":"1"
		}
			function savesubmit(){
				var $bid=$("#BigDropList").val().trim();
				var $sid=$("#SmallDropList").val().trim();
				var $title=$("#title");
				if ($title.val().trim()===''){
                    layer.msg('请输入新闻标题',{icon:0, offset: '25%'});
                    $title.focus();
                    return ;
                }
                var $author=$("#author");
				if ($author.val().trim()===''){
                    layer.msg('请输入文章编辑', {icon:0, offset: '15%'});
                    $author.focus();
                    return ;
                }
                var $origin=$("#origin");
				if ($origin.val().trim()===''){
                    layer.msg('请输入文章来源', {icon:0, offset: '15%'});
                    $origin.focus();
                     return ;
                 }
                var $context=UE.getEditor('editor').getContent()
                if ($context ===''){
                     layer.msg('新闻内容为空', {icon:0,offset: '15%'});
                    UE.getEditor('editor').focus();
                    return
                }
				var $datenow=$("#date_now");
				if ($datenow.val().trim()===''){
                    layer.tips('请设置时间', $datenow);
                    $datenow.focus();
                    return ;
                }
                 $.lintul('/admin/article/addnew',{bid:$bid,sid:$sid,title:$title.val().trim(),author:$author.val().trim(),origin:$origin.val().trim(),context:$context,lunbotu:0,datenow:$datenow.val(),hitscount:$("#hits_count").val()},function(data){
                 	if (data.status === 1) {
                        layer.msg('发布新闻成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            window.location.href="/admin";
                        });
					}else if(data.status === 12){
						layer.msg('发布新闻失败,同类别新闻标题已存在', { offset: '15%', icon: 5 });
                    } else {
                        layer.msg('发布新闻失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
	}
            function changeSmall(obj){
				var $thissmall=document.getElementById("smallval"+obj.value)
				if($thissmall=== null){
					 document.getElementById("SmallDropList").innerHTML="<option value='0'>无</option>"
				}else{
					document.getElementById("SmallDropList").innerHTML=document.getElementById("smallval"+obj.value).value
				}
            }
            $(function(){
					var $bid=$("#BigDropList").val().trim();
					document.getElementById("SmallDropList").innerHTML=document.getElementById("smallval"+$bid).value
            		var now = (new Date());
            		var year=""+now.getFullYear();
            		var month=now.getMonth()+1;
            		var date=now.getDate();
            		var hours=now.getHours();
            		var minutes=now.getMinutes();
            		var seconds=now.getSeconds();
            		var time_now=year + "-" + Appendzero (month) + "-" + Appendzero (date) + " " + Appendzero (hours) + ":" + Appendzero (minutes)+":"+Appendzero (seconds)
            		$("#date_now").val(time_now);

                    laydate({
                        elem:'#date_now',
                        format: 'YYYY-MM-DD hh:mm:ss', //日期格式
                        istime: true, //是否开启时间选择
                    }
                        );

            });
            function Appendzero (obj) {
       		if (obj < 10) return "0" + obj; else return obj;
  	}
  	function ValidateNumber(e, pnumber){
		if (!/^\d+$/.test(pnumber)){
		e.value = /^\d+/.exec(e.value);}
		return false;
		}
        </script>
</body>
</html>
